<?php
if (!defined('__COLA_DIR__')) exit;

/**
 * 服务器信息组件
 *
 * @author edikud
 * @package Widget
 * @copyright Copyright (c) 2019 Cola (http://www.mcooo.com)
 * @license GNU General Public License 2.0
 */
class Widget_OS extends Cola
{
    /**
     * 数据库对象
     *
     * @access protected
     * @var Db
     */
    protected $db;
	
    protected $isIniGet;
	

    /**
     * 构造函数,初始化组件
     *
     * @access public
     * @param mixed $request request对象
     * @param mixed $response response对象
     * @param mixed $params 参数列表
     * @return void
     */
    public function __construct($request, $response, $params = NULL)
    {
        parent::__construct($request, $response, $params);

        /** 初始化数据库 */
        $this->db = Db::instance();
		
		/** 考虑禁用 ini_get 的服务器 */
        $this->isIniGet = function_exists('ini_get');
		
		/** 插件接口 */
		//HOOK PLUG_OS($this);
    }
	
    protected function ___OS()
    {
        return PHP_OS;
    }

    protected function ___server()
    {
        return $this->request->getServer('SERVER_SOFTWARE');
    }

    protected function ___PHPVersion()
    {
        return PHP_VERSION;
    }

    protected function ___postMaxSize()
    {
        return $this->isIniGet ? ini_get('post_max_size') : 'unknown';
    }

    protected function ___uploadMaxFilesize()
    {
        return $this->isIniGet ? ini_get('upload_max_filesize') : 'unknown';
    }
    protected function ___allowUrlFopen()
    {
        return $this->isIniGet ? (ini_get('allow_url_fopen') ? 'yes' : 'no') : 'unknown';
    }
    protected function ___safeMode()
    {
        return $this->isIniGet ? (ini_get('safe_mode') ? 'yes' : 'no') : 'unknown';
    }
    protected function ___maxExecutionTime()
    {
        return $this->isIniGet ? ini_get('max_execution_time') : 'unknown';
    }	
    protected function ___memoryLimit()
    {
        return $this->isIniGet ? ini_get('memory_limit') : 'unknown';
    }	
    protected function ___clientIP()
    {
        return $this->request->getIp();
    }	
	
    protected function ___serverIP()
    {
        return $this->request->getServer('REMOTE_ADDR');
    }
    protected function ___dbType()
    {
        return $this->db->getAdapterName();
    }
    protected function ___dbVersion()
    {
        return $this->db->version();
    }
}
